/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import engine.Singleton;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alexx
 */
public class MultiThreadedServer extends Thread
{
    static final int PORT = 8888;
    public static void main(String[] args) throws IOException
    {
        ServerSocket s = new ServerSocket(PORT);
        System.out.println("Server Started");
        Singleton.getInstance();
        try
        {
            while (true)
            {
                Socket socket = s.accept();
                try
                {
                    ServeOneThread clients = new ServeOneThread(socket);
                    
                }
                catch (IOException e)
                {
                    socket.close();
                }
            }
        }
        finally
        {
            s.close();
        }
    }
    
//     @Override
//    public void run( ) {
//      ServerSocket s = null;
//      try {
//         s = new ServerSocket(PORT);
//      } catch (IOException ex) {
//         Logger.getLogger(MultiThreadedServer.class.getName()).log(Level.SEVERE, null, ex);
//      }
//         while (true)
//            {
//                Socket socket = null;
//         try {
//            socket = s.accept();
//         } catch (IOException ex) {
//            Logger.getLogger(MultiThreadedServer.class.getName()).log(Level.SEVERE, null, ex);
//         }
//                try
//                {
//                    //new ServeOneThread(socket);
//                    ServeOneThread clients = new ServeOneThread(socket);
//                //    Singleton.clients.add(clients);
//                }
//                catch (IOException e)
//                {
//            try {
//               socket.close();
//            } catch (IOException ex) {
//               Logger.getLogger(MultiThreadedServer.class.getName()).log(Level.SEVERE, null, ex);
//            }
//                }
//            }
//    }
}
